<template>
	<view class="content">
		<u-navbar bgColor="transparent" titleStyle="color:#fff" title="确认订单" leftIconColor="#fff" :autoBack="true"
			:placeholder="false">
		</u-navbar>
		<view style="height: 70rpx;"></view>
		<view class="order-box">
			<view class="order-info" @click="goAddress">
				<view class="order-left" v-if="addressinfo.name">
					<view class="order-head">
						<image src="../../../static/shop/address.png" mode=""></image>
						<view class="name">
							{{addressinfo.name}}
						</view>
						<view class="tell">
							{{addressinfo.tel}}
						</view>
					</view>
					<view class="address">
						{{addressinfo.address_detail}}{{addressinfo.address_all}}
					</view>
				</view>
				<view v-else class="order-left">添加默认地址</view>
				<u-icon name="arrow-right" color="#ffffff" size="20"></u-icon>
			</view>
		</view>
		<view class="order-box">
			<view class="goods">
				<view class="goods-info">
					<view class="goods-img">
						<image :src="info.logo" mode=""></image>
					</view>
					<view class="goods-explain">
						<view class="goods-name">
							{{info.goods_name}}
						</view>
						<view class="goods-num">
							×1
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="order-box">
			<view class="freight">
				<view>
					运费
				</view>
				<view>
					免运费
				</view>
			</view>
		</view>
		<view class="btn-box">
			<u-button style="color: #000;" shape="circle" type="primary"
				color="linear-gradient( 90deg, #C8F673 0%, #98F083 100%)" @click="gobuy" text="兑换"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {},
				list: [],
				addressinfo: {}
			}
		},
		onLoad(e) {
			this.info = JSON.parse(decodeURIComponent(e.item))
		},
		onShow() {
			this.addressinfo = {}
			this.getaddlist()
		},
		methods: {
			gobuy() {
				if (!this.addressinfo.id) {
					uni.showToast({
						title: '请选择默认地址！',
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					mask: true
				})
				let params = {
					address_id: this.addressinfo.id,
					goods_id:this.info.id
				}
				this.$Request({
					method: 'POST',
					url: '/api/shop/confirmOrder_quan',
					data: params
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						uni.showToast({
							title:'兑换成功！',
							icon:'none'
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1000)
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
			},
			getaddlist() {
				let params = {

				}
				this.$Request({
					method: 'POST',
					url: '/api/shop/addresslist',
					data: params
				}).then(res => {
					if (res.code == 1) {
						this.list = res.data
						this.list.map(item => {
							if (item.status == 1) {
								this.addressinfo = item
							}
						})
					}
				})
			},
			goAddress() {
				uni.navigateTo({
					url: '/pages/shop/address/index'
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #17191A;
	}
</style>
<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background-image: url('../../../static/my/my-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 558rpx;
		padding: 30rpx;

		.btn-box {
			width: 90%;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 30rpx;
			margin: auto;
		}

		.order-box {
			padding: 30rpx;
			background: linear-gradient(134deg, rgba(255, 227, 211, 0.06) 0%, rgba(67, 130, 84, 0.26) 100%);
			border: 4rpx solid rgba(108, 233, 137, 0.12);
			border-radius: 30rpx;
			margin-bottom: 30rpx;

			.order-info {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.order-left {
					color: #ffffff;
					font-size: 28rpx;
					font-weight: bold;

					.order-head {
						display: flex;
						align-items: center;

						image {
							width: 25.53rpx;
							height: 31rpx;
						}

						.name {
							margin-left: 10rpx;
						}

						.tell {
							margin-left: 50rpx;
						}
					}

					.address {
						color: #999;
						font-size: 24rpx;
						margin-top: 15rpx;
					}
				}
			}

			.goods {
				.goods-info {
					display: flex;

					.goods-img {
						width: 150rpx;
						height: 150rpx;
						padding: 20rpx;
						text-align: center;
						border-radius: 20rpx;
						background-color: #1D2123;

						image {
							width: 70rpx;
							height: 120rpx;
						}
					}

					.goods-explain {
						margin-left: 20rpx;

						.goods-name {
							font-size: 28rpx;
							font-weight: bold;
							color: #ffffff;
						}

						.goods-num {
							margin-top: 20rpx;
							font-size: 24rpx;
							color: #999;
						}
					}
				}
			}

			.freight {
				display: flex;
				justify-content: space-between;
				font-size: 26rpx;
				color: #ffffff;
				font-weight: bold;
			}
		}
	}
</style>